/*
 * CustomImplement.h
 *
 *  Created on: 2021年11月6日
 *      Author: ITry
 */

#ifndef INC_CUSTOMIMPLEMENT_H_
#define INC_CUSTOMIMPLEMENT_H_

#include "WFSensor.h"

#define IIC_TEST
//#define SPI4_TEST
//#define SPI3_TEST

#if defined IIC_TEST
	#include "IIC_UNIT.h"
#elif defined SPI4_TEST
	#include "SPI4_UNIT.h"
#elif defined SPI3_TEST
	#include "SPI3_UNIT.h"
#endif

int read_byte (void* bus_param, uint8_t dev_addr, uint8_t reg_addr, uint8_t *data){
#if defined IIC_TEST
	return iic_read_byte(bus_param, dev_addr, reg_addr, data);
#elif defined SPI4_TEST
	return spi4_read_byte(bus_param, dev_addr, reg_addr, data);
#elif defined SPI3_TEST
	return spi3_read_byte(bus_param, dev_addr, reg_addr, data);
#endif
	return 0;
}

int read_bytes (void* bus_param, uint8_t dev_addr, uint8_t reg_addr, uint8_t len, uint8_t *data){
#if defined IIC_TEST
	return iic_read_bytes(bus_param, dev_addr, reg_addr, len, data);
#elif defined SPI4_TEST
	return spi4_read_bytes(bus_param, dev_addr, reg_addr, len, data);
#elif defined SPI3_TEST
	return spi3_read_bytes(bus_param, dev_addr, reg_addr, len, data);
#endif
	return 0;
}

int write_byte (void* bus_param, uint8_t dev_addr, uint8_t reg_addr, uint8_t data){
#if defined IIC_TEST
	return iic_write_byte(bus_param, dev_addr, reg_addr, data);
#elif defined SPI4_TEST
	return spi4_write_byte(bus_param, dev_addr, reg_addr, data);
#elif defined SPI3_TEST
	return spi3_write_byte(bus_param, dev_addr, reg_addr, data);
#endif
	return 0;
}

void wf_delayMs(uint16_t t){
	HAL_Delay(t);
}

const struct bus_handler handler = {
      .read_byte = read_byte,
      .read_bytes = read_bytes,
      .write_byte = write_byte,
      .bus_param = NULL,
	  .wf_delayMs = wf_delayMs
};

#endif /* INC_CUSTOMIMPLEMENT_H_*/
